Skip to content

Add support set in fields stdClass in Structure::prepareToStore #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

Add support set in fields stdClass in Structure::prepareToStore #173

wants to merge 2 commits into from

Conversation

MCubs
Copy link

@MCubs MCubs commented Jan 25, 2019

Hello,

I created a patch that adds the ability to save an empty object to the collection.
This need arose due to the nature of my system.
The save method in the class Document saves an empty object as an array.
Playback example:
I have Model Car extended Document.
Create $car = new Car();
$car->set('human-id', 1)->save();
$car->update(["human-id" => 1], ['$set' =>["markets-data.1" => ["car" => 1]]]);
Data in DB:

{
	"_id" : ObjectId(""),
	"markets-data" : {
		"1" : {"car": 1}
	},
	"human-id" : 1
}

$car->update(["human-id" => 1], ['$unset' =>["markets-data.1" => ["car" => 1]]]);
Data in DB:

{
	"_id" : ObjectId(""),
	"markets-data" : {},
	"human-id" : 1
}

$car->save();
Data in DB:

{
	"_id" : ObjectId(""),
	"markets-data" : array(),
	"human-id" : 1
}

Here is an example of how update works in the native view:

> db.vehicle.update({"human-id": 36}, {'markets-data': {}, "human-id": 36});
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })
> db.vehicle.find({"human-id": 36}, {'markets-data': 1, 'human-id': 1}).pretty();
{
	"_id" : ObjectId(""),
	"markets-data" : {},
	"human-id" : 36
}

How to use my patch:
Create $car = new Car();
$car->set('human-id', 1)->save()
Data in DB:

{
	"_id" : ObjectId(""),
	"human-id" : 1
}

$car->set('markets-data', new \stdClass)->save();
{
"_id" : ObjectId(""),
"markets-data" : {},
"human-id" : 1
}

@@ -399,6 +399,11 @@ public static function prepareToStore($value)
return $value->toArray();
}

// stdClass
if ($value instanceof \stdClass) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you broke tests

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought that was dejawoo but #143 there is already closed issue with same pull request )))

Copy link
Owner

@sokil sokil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#143

There is problem how to identify is this empty object {} or list []

And there is a reason to specify types #144

@@ -399,6 +399,11 @@ public static function prepareToStore($value)
return $value->toArray();
}

// stdClass
if ($value instanceof \stdClass) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought that was dejawoo but #143 there is already closed issue with same pull request )))

@MCubs
Copy link
Author

MCubs commented Jan 26, 2019

When i can get instruction for run docker?

@sokil
Copy link
Owner

sokil commented Jan 26, 2019

@MCubs MCubs closed this Jan 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants